package net.zjitc.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * @Author admin
 * @Date 2019/4/24 9:05
 */
public class test2 {
    public static void main(String[] args) {
        /*1.注册驱动
        * 2. 获得数据库连接
        * 3.获得能操作的sql的语句的对象
        *  */
        Connection conn=null;
        Statement stmt=null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            String url="jdbc:mysql://localhost:3306/hxy";
            String user ="root";
            String password="123456";
            conn= DriverManager.getConnection(url,user,password);
            stmt=conn.createStatement();
            String sql="UPDATE USER SET age=20 WHERE NAME='李四'";
            int c=stmt.executeUpdate(sql);
            System.out.println("影响了"+c+"行");
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
           if (stmt!=null){
               try {
                   stmt.close();
               } catch (SQLException e) {
                   e.printStackTrace();
               }
           }
             if (conn!=null){
                 try {
                     conn.close();
                 } catch (SQLException e) {
                     e.printStackTrace();
                 }
             }

        }
    }
}
